package com.springboot.frame;

import org.springframework.util.CollectionUtils;
import java.util.*;

/**
 * JDBC 工具类
 *
 * 參考mybatis-plus
 * @since 2016-12-05
 */
public class JdbcUtils {

    /**
     * 获取sql语句开头部分
     * 只记录增删改查
     * @param sql ignore
     * @return ignore
     */
    private int indexOfSqlStart(String sql) {
        String upperCaseSql = sql.toUpperCase();
        Set<Integer> set = new HashSet<>();
        set.add(upperCaseSql.indexOf("SELECT "));
        set.add(upperCaseSql.indexOf("UPDATE "));
        set.add(upperCaseSql.indexOf("INSERT "));
        set.add(upperCaseSql.indexOf("DELETE "));
        set.remove(-1);
        if (CollectionUtils.isEmpty(set)) {
            return -1;
        }
        List<Integer> list = new ArrayList<>(set);
        list.sort(Comparator.naturalOrder());
        return list.get(0);
    }
}
